#include "VSaveQuestion.h"
#include "ui_VSaveQuestion.h"

#include <QVariant>
#include <QFileInfo>
#include <QDebug>

VSaveQuestion::VSaveQuestion(QWidget *parent, QStringList paths) :
    QDialog(parent),
    ui(new Ui::VSaveQuestion)
{
    ui->setupUi(this);
    foreach(QString path, paths)
    {
        auto item = new QListWidgetItem();
        item->setFlags(Qt::ItemIsUserCheckable|
                       Qt::ItemIsEnabled);
        item->setCheckState(Qt::Checked);
        item->setData(Qt::UserRole, QVariant::fromValue(path));
        item->setText(QFileInfo(path).fileName() + "  [" + path+"]");
        ui->listWidget->addItem(item);
    }
}

VSaveQuestion::~VSaveQuestion()
{
    delete ui;
}

void VSaveQuestion::on_btn_yes_clicked()
{
    _save_paths.clear();
    for(int i=0; i<ui->listWidget->count(); i++)
    {
        auto item = ui->listWidget->item(i);
        if(item->checkState() == Qt::Checked)
        {
            _save_paths.append(item->data(Qt::UserRole).value<QString>());
        }
    }
    this->accept();
}

void VSaveQuestion::on_btn_no_clicked()
{
    this->accept();
}

void VSaveQuestion::on_btn_cancel_clicked()
{
    this->reject();
}
